<?php
/*
 * 
 * on a déjà ajouté :
 * 		des types de produits
 * 		des produits
 * 
 * on ajoute :
 * 		des utilisateurs
 */

namespace Drinkiit\BlogBundle\DataFixtures\ORM;


use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;

use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

use Drinkiit\UtilisateurBundle\Entity\UtilisateurApp;

class LoadUtilisateurData extends AbstractFixture implements ContainerAwareInterface, OrderedFixtureInterface {
	
	private $container ;
	
	public function setContainer(ContainerInterface $container = null) {
		$this->container = $container ;
	}
	
    public function load(ObjectManager $manager)
    {
		// liste des rôles des utilisateurs
        $role_admin = 'ROLE_ADMIN' ;
        $role_user = 'ROLE_USER' ;
        
		$factory = $this->container->get('security.encoder_factory');
		
		// liste des utilisateurs de base
		$drinkiit = new UtilisateurApp() ;
		$drinkiit->setUsername('Drinkiit') ;
		$drinkiit->setUsernameCanonical('drinkiit') ;
		$drinkiit->setEmail('drinkiit.webmaster@gmail.com') ;
		$drinkiit->setEmailCanonical('drinkiit.webmaster@gmail.com') ;
			$encoder = $factory->getEncoder($drinkiit) ;
		$drinkiit->setPassword($encoder->encodePassword('adminpass', $drinkiit->getSalt())) ;
        $drinkiit->addRole($role_admin) ;
        $drinkiit->setEnabled(true) ;
		$manager->persist($drinkiit) ;
		$this->addReference('drinkiit', $drinkiit);
		
		$admin = new UtilisateurApp() ;
		$admin->setUsername('Admin') ;
		$admin->setUsernameCanonical('admin') ;
		$admin->setEmail('xaviercavarelli@yahoo.fr') ;
		$admin->setEmailCanonical('xaviercavarelli.webmaster@yahoo.fr') ;
			$encoder = $factory->getEncoder($admin) ;
		$admin->setPassword($encoder->encodePassword('root', $admin->getSalt())) ;
        $admin->addRole($role_admin) ;
        $admin->setEnabled(true) ;
		$manager->persist($admin) ;
		$this->addReference('admin', $admin);

		
		$anonymous = new UtilisateurApp() ;
		$anonymous->setUsername('anonymous') ;
		$anonymous->setUsernameCanonical('anonymous') ;
		$anonymous->setEmail('anonymous@gmail.com') ;
		$anonymous->setEmailCanonical('anonymous.webmaster@gmail.com') ;
			$encoder = $factory->getEncoder($anonymous) ;
		$anonymous->setPassword($encoder->encodePassword('userpass', $anonymous->getSalt())) ;
        $anonymous->addRole($role_user) ;
        $anonymous->setEnabled(true) ;
		$manager->persist($anonymous) ;
		$this->addReference('anonymous', $anonymous);
		
		$TEAM6767 = new UtilisateurApp() ;
		$TEAM6767->setUsername('TEAM6767') ;
		$TEAM6767->setUsernameCanonical('team6767') ;
		$TEAM6767->setNom('Muller') ;
		$TEAM6767->setPrenom('Timothée') ;
		$TEAM6767->setEmail('team6767@gmail.com') ;
		$TEAM6767->setEmailCanonical('team6767.webmaster@gmail.com') ;
			$encoder = $factory->getEncoder($TEAM6767) ;
		$TEAM6767->setPassword($encoder->encodePassword('mdp', $TEAM6767->getSalt())) ;
        $TEAM6767->addRole($role_user) ;
        $TEAM6767->setEnabled(true) ;
		$manager->persist($TEAM6767) ;
		$this->addReference('TEAM6767', $TEAM6767);
		
		$dwarf = new UtilisateurApp() ;
		$dwarf->setUsername('Dwarf') ;
		$dwarf->setUsernameCanonical('dwarf') ;
		$dwarf->setNom('Cavarelli') ;
		$dwarf->setPrenom('Xavier') ;
		$dwarf->setEmail('xaviercavarelli@gmail.com') ;
		$dwarf->setEmailCanonical('xaviercavarelli.webmaster@gmail.com') ;
			$encoder = $factory->getEncoder($dwarf) ;
		$dwarf->setPassword($encoder->encodePassword('17', $dwarf->getSalt())) ;
        $dwarf->addRole($role_user) ;
        $dwarf->setEnabled(true) ;
		$manager->persist($dwarf) ;
		$this->addReference('dwarf', $dwarf);
		
		$eclair = new UtilisateurApp() ;
		$eclair->setUsername('Eclair') ;
		$eclair->setUsernameCanonical('eclair') ;
		$eclair->setNom('Rybak') ;
		$eclair->setPrenom('Jonathan') ;
		$eclair->setEmail('rybak.jonathan@gmail.com') ;
		$eclair->setEmailCanonical('rybak.jonathan.webmaster@gmail.com') ;
			$encoder = $factory->getEncoder($eclair) ;
		$eclair->setPassword($encoder->encodePassword('aubergine', $eclair->getSalt())) ;
        $eclair->addRole($role_user) ;
        $eclair->setEnabled(true) ;
		$manager->persist($eclair) ;
		$this->addReference('eclair', $eclair);
		
		
		$manager->flush() ;
	}
	
	
	public function getOrder()
    {
        return 3; 
    }
}
?>
